package com.ggj2013.hbh;
import haxe.macro.Compiler;
import nme.display.Bitmap;
import nme.display.MovieClip;
import com.ggj2013.hbh.utils.HitBox;
import com.ggj2013.hbh.utils.Tools;
import com.ggj2013.hbh.utils.CollisionDetection;
import nme.display.Sprite;

/**
 * @author Kristian Fischer, Jonathan Moriarty
 */

class Item extends MovieClip
{	
	public static var NUM_ITEMS:Int = 19;
	
	public static var UNIFORM:Int = 0;
	public static var MIRROR:Int = 1;
	public static var MANIFEST:Int = 2;
	public static var GUN:Int = 3;
	public static var EVSUIT:Int = 4;
	public static var BELT:Int = 5;
	public static var CIGARETTES:Int = 6;
	public static var WINE:Int = 7;
	public static var WURLITZER:Int = 8;
	public static var MEDKIT:Int = 9;
	public static var CAPLOG:Int = 10;
	public static var SHIPLOG:Int = 11;
	public static var PENNY:Int = 12;
	public static var POWER_CONSOLE:Int = 13;
	public static var POD_CONSOLE:Int = 14;
	public static var COMM_CONSOLE:Int = 15;
	public static var BRIDGE_CONSOLE:Int = 16;
	public static var LADDER:Int = 17;
	public static var AIRLOCK_CONSOLE:Int = 18;
	
	public static var names:Array<Dynamic> = [ 	"uniform", "mirror", "manifest", "gun",
												"evsuit", "belt", "cigarettes", "wine",
												"wurlitzer", "medkit", "caplog", "shiplog", "penny",
												"console", "console", "console", "console",
												"ladder", "floorlock"  ];
	
	public static var descriptions:Array<Dynamic> = [ 	"A storage locker.\nInside is a uniform; it fits.\nThe name on the chest reads 'Prof. Fether.'\nIt fits you as well.", 
														"A movement catches your eye.\nIt is a mirror.\nYou recognize the face as your own.\nFirst a name, now a face.", 
														"A crew manifest for the 'DSV Maison de Sante.'\nEach name stirs your memories;\n you find yourself listed as ship's science officer.", 
														"A side arm.\nYou check and find it loaded, but one round is missing...\nYou strap it on and feel safer already.",
														"An Envirosuit with your name on it.\nThe other suit racks are all empty...\nThis could prove useful.\n", 
														"A tool belt.\nThe tools feel heavy in your hands,\nbut you know what most of them are for.", 
														"A pack of cigarettes;\nsurgeon general be damned!\nYou light one up and inhale deeply.\nMmmm... you are in flavor country.", 
														"A bottle of wine.\nUncorking it, you take a sip.\nMmmm... Amontillado; a fine vintage.\nWarmth spreads through you as you drink.",
														"A Wurlitzer.\nThe lights create weird shadows.\nYou press 'B-17'; a sad song plays.\nYour eyes mist as bittersweet memories fill you...",
														"Emergency medical supplies.\nYou know how to use these;\nif only you had a patient to work on.\n",
														"The Captain's Logbook.\nFor the love of God, Captain Montresor;\nyou recognize the name of your lover!\n", 
														"The Ship's Logbook.\nThe last entry references the 'Fortunato';\nthe ship's escape craft.\nWhy did they leave without you?", 
														"See a penny, pick it up...",
														"The Power Room.\nRolling up your sleeves you get to work...\nSweat and grease stain your clothes,\nbut for a moment the lights flicker back on.", 
														"The Escape Craft Dock.\n The craft is gone;\nyou recall feeling the ship shudder as it jettisoned.\nWhat made them leave?\n", 
														"The Ship's Communications Room.\nThe radio has minimal power;\njust enough for one distress call...\n'Mayday, mayday! Please respond!'\nNo answer...", 
														"The Ship's Bridge.\nYou open the massive view ports.\nYou gasp as your eyes take in... nothing.\nInky blackness and nothing else.",
														"A stairwell leading to the lower levels of the ship.\nWhat more lays below waiting to be uncovered?", 
														"The Ship's Airlock.\nWith mounting dread you realize the damned heartbeat has lead you here.\nIt must be coming from outside!\nYou feel compelled to leave the ship; no matter the consequences.\nYou must escape!"  ];

	public static var sanityGains:Array<Dynamic> = [	20.0, 20.0, 20.0, 20.0,
														30.0, 30.0, 30.0, 30.0,
														40.0, 40.0, 40.0, 40.0,
														50.0, 50.0, 50.0, 50.0,
														40.0, 10.0, 0.0  ];
	public var sprite:Bitmap;
	public var detailSprite:Bitmap;
	public var hitBox:HitBox;
	
	
	
	public var itemName:String;
	public var type:Int;
	public var description:String;
	public var sanityGain:Float;
	public var remove:Bool;
	
	public function new( l_type:Int, xPos:Float, yPos:Float ) 
	{
		super();
		
		type = l_type;
		
		itemName = Item.names[ l_type ];
		
		this.x = xPos;
		this.y = yPos;
		
		description = Item.descriptions[ l_type ];
		this.sanityGain = Item.sanityGains[ l_type ];
		
		this.sprite = Tools.loadBitmap( itemName + "_small" );
		addChild( sprite );
		
		this.hitBox = new HitBox( sprite.width, sprite.height, 0xffffff );
		addChild( hitBox );
		
		this.scaleX = this.scaleY = 2.0;
		
		remove = false;
	}
	
	public function displayItem():Void {
		//Code for displaying item description/info
	}
	
	public function update( l_deltaTime:Int ):Void {
		//Code for displaying item description/info
		if ( InputManager.isKeyPressed( InputManager.E_KEY ) && !remove && 
			 CollisionDetection.isPixelPerfectColliding( LevelScreen.player.hitBox, this.hitBox, HBH.levelScreen, true, 0 ) ) 
		{
			//trace("E key");
			//trace(LevelScreen.player.currentSanity);
			//trace(description);
			LevelScreen.player.currentSanity += sanityGain;
			remove = true;
		}
	}
}